<template>
  <div class="bg-form">
    <el-form
      :model="addForm"
      label-width="130px"
      :show-message="false"
      :rules="addFormRules"
      ref="addForm"
    >
      <el-row>
        <el-col>调拨入库基础信息 {{ addForm.code }}</el-col>
      </el-row>
      <el-divider content-position="center"></el-divider>
      <el-row>
        <el-col :span="6">
          <el-form-item label="入库门店:" prop="storeName">
            <el-input disabled v-model="addForm.storeName" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="出库门店:" prop="outStoreName">
            <el-input
              disabled
              v-model="addForm.outStoreName"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="车架号:" prop="vin">
            <el-input disabled v-model="addForm.vin" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="发动机号:" prop="engineModel">
            <el-input
              disabled
              v-model="addForm.engineModel"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="6">
          <el-form-item label="品 牌:" prop="carBrandName">
            <el-input
              disabled
              v-model="addForm.carBrandName"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="6">
          <el-form-item label="车 系:" prop="seriesName">
            <el-input
              disabled
              v-model="addForm.seriesName"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="车 型:" prop="modelName">
            <el-input
              disabled
              v-model="addForm.modelName"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="增配件及价格明细:" prop="addPartsDetail">
            <el-input
              disabled
              v-model="addForm.addPartsDetail"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="车身颜色:" prop="outColor">
            <el-input disabled v-model="addForm.outColor" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="内饰颜色:" prop="inColor">
            <el-input disabled v-model="addForm.inColor" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="车顶颜色:" prop="roofColor">
            <el-input disabled v-model="addForm.roofColor" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="前装及价格明细:" prop="qzDetail">
            <el-input disabled v-model="addForm.qzDetail" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="采购单价:" prop="guidePrice">
            <el-input
              disabled
              v-model="addForm.guidePrice"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col>调拨入库确认信息</el-col>
      </el-row>
      <el-divider content-position="center"></el-divider>
      <el-row>
        <el-col :span="6">
          <el-form-item label="仓 库:" prop="storageId">
            <el-select
              class="w-100"
              clearable
              v-model="addForm.storageId"
              placeholder="请选择"
              @change="getStorageSite"
            >
              <el-option
                v-for="item in storageList"
                :key="item.id"
                :value="item.id"
                :label="item.storageName"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="仓 位:" prop="storageSiteId">
            <el-select
              class="w-100"
              clearable
              v-model="addForm.storageSiteId"
              placeholder="请选择"
            >
              <el-option
                v-for="item in storageSitList"
                :key="item.id"
                :value="item.id"
                :label="item.storageSiteName"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="排放标准:" prop="emissionStandards">
            <el-select
              class="w-100"
              clearable
              v-model="addForm.emissionStandards"
              placeholder="请选择"
            >
              <el-option
                v-for="item in dict['排放标准']"
                :key="item.index"
                :value="item.value"
                :label="item.text"
              />
            </el-select>
          </el-form-item>
        </el-col>
<el-col :span="6">
              <el-form-item label="预计到达时间:" prop="estimatedTime">
                <el-date-picker
                  v-model="addForm.estimatedTime"
                  type="date"
                  class="w-100"
                  placeholder="预计到达时间"
                  clearable
                  value-format="yyyy-MM-dd HH:mm:ss"
                />
              </el-form-item>
            </el-col>
              <el-col :span="6">
              <el-form-item label="物流公司:" prop="logisticsCompany">
                <el-input
                  v-model="addForm.logisticsCompany"
                  class="w-100"
                  placeholder="物流公司"
                  clearable
                />
              </el-form-item>
            </el-col>
              <el-col :span="6">
              <el-form-item label="配送方式:" prop="modeDistribution">
                <el-input
                  v-model="addForm.modeDistribution"
                  class="w-100"
                  placeholder="配送方式"
                  clearable
                />
              </el-form-item>
            </el-col>
        <el-col :span="24" align="right">
          <el-button type="primary"   v-permission="'allotStorage:update'"  @click="onSubmit('addForm')"
            >保存</el-button
          >
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import { getDict } from '@/utils/index'
import {
  addData,
  findByInfoId,
} from '@/api/pre-sale/newCarStock/putInStorageManagement/transferInventory'
import { findByStore } from '@/api/after-sale/storehouseManage/warehouseManage'
import { storageSite } from '@/api/pre-sale/boutiqueStock/inventoryCheck'
export default {
  props: ['id'],
  data() {
    return {
      addForm: {
        id: this.id,
        storageId: '',
        storageSiteId: '',
        emissionStandards: '',
      },
      form: {},
      addFormRules: {
        storageId: [{ required: true, message: '请选择仓库', trigger: 'change' }],
        storageSiteId: [
          { required: true, message: '请选择', trigger: 'change' },
        ],
        emissionStandards: [
          { required: true, message: '请选择', trigger: 'change' },
        ],
      },
      storageList: [],
      storageSitList: [],
      dict: {},
    }
  },
  mounted() {
    this.dict = getDict(['排放标准'])
    this.getDetail()
  },
  methods: {
    // 获取仓库
    async getWareHouse(id) {
      this.storeId = id
      let { data } = await findByStore(id)
      this.storageList = data
    },
    // 获取仓位
    async getStorageSite(value) {
      const param = {
        storageId: value,
        storeId: this.addForm.storeId,
      }
      let { data } = await storageSite(param)
      this.storageSitList = data.content || []
    },
    // 保存
    onSubmit(formName) {
      this.$refs[formName].validate(async (valid) => {
        if (valid) {
          const { id, vin, engineModel, storageId, storageSiteId, emissionStandards, estimatedTime, logisticsCompany, modeDistribution } = this.addForm
          const { success } = await addData({
            id,
            vin,
            engineModel,
            storageId,
            storageSiteId,
            emissionStandards,
            estimatedTime,
            logisticsCompany,
            modeDistribution
          })
          if (success) {
            this.$message({
              message: '操作成功',
              type: 'success'
            })
            this.$router.push({ path: '/newCarStock/putInStorageManagements/transferInventory' })
          } else {
            this.$message.error('操作失败')
          }
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    async getDetail() {
      await findByInfoId(this.id).then((res) => {
        const { success, data } = res
        if (success) {
          this.getWareHouse(data.storeId)
          this.addForm = { ...this.addForm, ...data }
          if (this.addForm.storageId) {
            this.getStorageSite(this.addForm.storageId)
          }
        }
      })
    },
  },
}
</script>
<style lang="scss" scoped>
.bg-form {
  background: #ffffff;
  padding: 20px;
}
</style>

